/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.new9uy.tetris.game.player;

import java.util.Objects;
import org.new9uy.tetris.game.type.Game;
import org.new9uy.tetris.model.Gravity;
import org.new9uy.tetris.model.Matrix;
import org.new9uy.tetris.model.Next;
import org.new9uy.tetris.model.Score;

/**
 *
 * @author Overmind
 */
public abstract class AbstractPlayer
    implements Player
{
    private Gravity gravity;
    private String name;
    
    private boolean aiPlayer;

    public AbstractPlayer(String name, boolean aiPlayer)
    {
        this(name, 0, aiPlayer);
    }
    
    public AbstractPlayer(String name,int startLvl, boolean aiPlayer)
    {
        this.aiPlayer = aiPlayer;
        this.name = name;
        
        gravity = new Gravity(startLvl, Game.matrix,
                Game.next,
                Game.score);
        gravity.setName("BotGravity");
        
        setUpBotMind(aiPlayer);
    }

    @Override
    public Gravity getGravity()
    {
        return gravity;
    }

    @Override
    public Matrix getMatrix()
    {
        return Game.matrix;
    }

    @Override
    public Next getNext()
    {
        return Game.next;
    }

    @Override
    public Score getScore()
    {
        return Game.score;
    }

    @Override
    public boolean isBot()
    {
        return aiPlayer;
    }

    @Override
    public String getName()
    {
        return name;
    }

    @Override
    public String toString()
    {
        return super.toString(); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public int hashCode()
    {
        int hash = 7;
        hash = 37 * hash + Objects.hashCode(this.gravity);
        hash = 37 * hash + Objects.hashCode(this.name);
        hash = 37 * hash + (this.aiPlayer ? 1 : 0);
        return hash;
    }

    @Override
    public boolean equals(Object obj)
    {
        if (obj == null)
        {
            return false;
        }
        if (getClass() != obj.getClass())
        {
            return false;
        }
        final AbstractPlayer other = (AbstractPlayer) obj;
        if (!Objects.equals(this.gravity, other.gravity))
        {
            return false;
        }
        if (!Objects.equals(this.name, other.name))
        {
            return false;
        }
        if (this.aiPlayer != other.aiPlayer)
        {
            return false;
        }
        return true;
    }

    private void setUpBotMind(boolean mind)
    {
        getMatrix().setBotMindOn(mind);
    }
    
    
}
